/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.templates.commands.TimedShootCatapult_CG;

/**
 *
 * @author Robotics
 */
public class DetectTargets extends CommandBase {
    
    public double Time = 0;
    public boolean isDone = false;
    public double actualDistance = 0;
    
    public DetectTargets(double Duration, double Distance) {
        // Use requires() here to declare subsystem dependencies
        requires(camera);
        actualDistance = 0;
        Time = Duration;
        actualDistance = Distance;
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        setTimeout(Time);
        isDone = false;
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        double cameraDistance = 0;
        try{
            cameraDistance = camera.findTargets();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if(cameraDistance >= (actualDistance - 1) && cameraDistance <= (actualDistance + 1)){
            isDone = true;
        }
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return isTimedOut() | isDone;
    }

    // Called once after isFinished returns true
    protected void end(){
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {

    }
}
